<?php
ob_start();
//error_reporting(0);
include('header.php');
include('menu.php');
include("connection/connection.php");
include('config.php');
$loginid=$_SESSION['loginid'];

if(isset($_REQUEST['mail']))
{
$ids=$_REQUEST['ids'];
$ids1=$_REQUEST['ids1'];
//print_r($_REQUEST['ids1']);
$i = implode(',',$ids);
$j = implode(',',$ids1);
foreach($ids as $frmid)
{
$queryUsr="select * from tbl_dtls_user_history where form_id='".$frmid."'";
												 $resultUsr=mysql_query($queryUsr);
												 $showUsr=mysql_fetch_row($resultUsr);
												 $usrlist=$showUsr[6]." ".$usrlist;
}												 
                         
	$user_type=$j;
	$q="SELECT emailid FROM tbl_dtls_createuser WHERE loginid='$loginid'";
	$res=mysql_query($q);
	$x=mysql_fetch_array($res);
	$from=$x['emailid'];
	//if($user_type!='ALL')
	//{
	$qry="SELECT emailid,usertype FROM tbl_dtls_createuser WHERE usertype in($user_type) and loginid!='$loginid'";
	//}
	//else 
	//{
	//	$qry="SELECT emailid FROM tbl_dtls_createuser WHERE loginid!='$loginid'";
	//}
	
	//echo $qry;
	$res1=mysql_query($qry);
	//$e=implode(',',$e);
	//print_r($e);
	
	//echo $q;
	//$res=mysql_query($q);
	//$x=mysql_fetch_array($res);
	//$from=$res1['emailid'];
	//echo $from;
	//$email = $_POST['email']; 
	//$email = mysql_fetch_array($res1);
	$subject = "Regarding invalid range entry"; 
	//while($formid=mysql_fetch_array($resultUser))
	//{
	//$message ="This form(" .$formid['form_id']. ") is filled by ".$formid['user_type']. " and the quality control parameter is //below/beyond the range.";
	$message ="This form ($i) is filled by ($usrlist) and the quality control parameter is below/beyond the range.";
	//$e=array();
	while($a=mysql_fetch_row($res1))	
	{
    	    
	
	 $qr="INSERT INTO tbl_dtls_compose(id, user_type, receiver, sender, sub, message, post_time) VALUES(NULL, '$a[1]', '$a[0]', '$from', '$subject', '$message', NOW())";
	//echo $qr;
	$r5=mysql_query($qr);	
	}
	if(mysql_affected_rows() > 0)
	{	
		echo'<span class="successmssg"><b>Congratulation!!</b><br/>Your mail is Successfully Sent. Now you can go on <a href="exceptioncol.php">Back</a> page</span>';
		$message = wordwrap($message,70);
		$header = "MIME-Version: 1.0\r\n"; 
		$header .="From:Ramky {$from}\r\n"; 
		mail($e, $subject, $message, $header); 
		exit();
	}
	else 
	{
		//echo "Some problem inserting record";
		echo'<h3>Sorry, some error occured, please try again after sometime.<h3>';
	}
	
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Exception</title>
<style type="text/css">
a{text-decoration:none;}
a:link
{
color:#006699;
}
a:visited
{
color:#006699;
}
a:active
{
color:#006699;
}
a:hover
{
color:#000000;
}
</style>
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<script language='javascript'>
checked=false;
function checkedAll () {

	var aa= document.getElementById('frm1');
	var chks = document.getElementsByName('ids1'+'[]');
	var chks1 = document.getElementsByName('ids'+'[]');
	 if (checked == false)
          {
           checked = true
          }
        else
          {
          checked = false
          }
		  //alert(aa.elements.length);
	for (var i = 0; i < aa.elements.length; i++) 
	{
	 
	 //aa.elements[i].checked = checked;
	  chks1[i].checked=checked;
	//chks[i].checked=false;
	 
	}
  }
  
  
function Checkone() {
 //var rad=document.getElementById('function_status'+p);
	 		//var rad1=document.getElementById('remarks'+p);
	 		//alert(rad.value);
		 var chks = document.getElementsByName('ids1'+'[]');
     	var hasChecked = false;
     		for (var i = 0; i < chks.length; i++)
     		{
     			if (chks[i].checked)
     			{
    				 hasChecked = true;
     				 break;
     			}
     		}
	 		if (hasChecked == false)
    		{
    			alert('Please Check at Least One in User Type');
				document.getElementById('ids1'+'[]').focus();
    			return false;
    		}
		
}

</script>
</head>
<body>
	<!--<table>
			<tr>
				<td><?php //include('header.php');?></td>
			</tr>
	</table>-->	
	<table width="443">
			<tr>
				<!--<td align="left" width="300"><?php //include('menu.php');?></td>-->
				<td valign="top">
	<table width="443">
			<tr>
				<!--<td align="left" width="300"><?php //include('menu.php');?></td>-->
				<td valign="top">
<table border="0" width="300px" id="table21" height="60%" cellspacing="1" style=" padding-top:0px" >
<tr bgcolor="FF9966">
	<td height="29" align="left" valign="top" bgcolor="#FF9966">&nbsp;</td>
	<td bgcolor="#FF9966" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#FF9966" align="left" valign="top" colspan="5">&nbsp;</td>
	<td height="29" align="left" valign="top" bgcolor="#FF9966">&nbsp;</td>
	<td bgcolor="#FF9966" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
	<td bgcolor="#E5E5E5" align="left" valign="top" width="1%">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top" width="5%">
	<!--<img border="0" src="images/my_pag2.jpg">--></td>
	<td bgcolor="#E5E5E5" align="left" width="91%" colspan="5">
	<span lang="en-us">&nbsp;</span><span lang="en-us" style="font-size: 8.5pt"><font face="Verdana" color="#006699"><b>QUALITY CONTROL</b></font></span></td>
	<td bgcolor="#E5E5E5" align="left" valign="top" width="1%">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top" width="5%">
</tr>

<tr>
	<td bgcolor="#E5E5E5" align="left" valign="top" colspan="7">
	<span style="font-size: 3pt" lang="en-us">&nbsp;</span></td>
	<td bgcolor="#E5E5E5" align="left" valign="top" colspan="7"></td>
</tr>
<tr>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top" colspan="5" bordercolor="#F2F2F2"></td>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td align="left" valign="top" colspan="5">
	<table border="0" width="750" id="table22" cellspacing="0" cellpadding="0">
								<!--<tr>
									<td bgcolor="#050505" height="1"></td>
								</tr>!-->
								<tr>
									<td>
										<table border="0" width="100%" id="table23" cellspacing="0" cellpadding="0">
											<tr>
												<td>&nbsp;</td>
											</tr>
											<tr>
												<td align="center">
													<b><font face="Verdana" style="font-size: 8.5pt" color="#000000">Range Exception</font></b>
												
										
													
													<form action="" method="post" name="frm1" id="frm1" onSubmit="return Checkone()">
													<table border="1" cellspacing="0" cellpadding="0" bordercolor="#C5D8EB" style="border: 1px solid #BBD1E8" bgcolor="#F9F9F9">
													
													<tr>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Select<input type="checkbox" onClick="checkedAll()"></font></td>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Form Id</font></td>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">User Type </font></td>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">User Name</font> </td>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Date</td>
													  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000">Parameter list(values below/beyond range)</font> </td>
													</tr>
													
												
													
													<?php
													$query="select distinct form_id from tbl_lookup_range_exception";
													$result=mysql_query($query);
													while($x=mysql_fetch_row($result))
													{
													?>
												<tr>
												
												  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><input type="checkbox" name="ids[]" id="ids[]" value="<?php echo "$x[0]";?>"></font></td>
												  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><a href="qc_view.php?cid=<?php echo "$x[0]"; ?> & cval=<?php
												
												$query1="select * from tbl_lookup_range_exception where form_id='".$x[0]."'";
													$result1=mysql_query($query1);
													while($x1=mysql_fetch_row($result1))
													{
												
												
												 echo $x1[3];
												 echo " ";
												 }?>"><?php echo $x[0];?></a></font></td>
												 <?php  
												 $queryUser="select * from tbl_dtls_user_history where form_id='".$x[0]."'";
												 $resultUser=mysql_query($queryUser);
												 $xUser=mysql_fetch_row($resultUser);
												 ?>
												  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><?php echo $xUser[6];?></font></td>
												  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><?php echo $xUser[7];?></font></td>
												  <td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><?php echo $xUser[5];?></font></td>
												  <td>
												  <table><tr><td><font face="Verdana" style="font-size: 8.5pt" color="#000000"><b>Parameter&nbsp;</b></font></td>
												 <?php
												 $query2="select * from tbl_lookup_range_exception where form_id='".$x[0]."'";
												 $result2=mysql_query($query2);
												 
												
													while($x2=mysql_fetch_row($result2))
													{
												?>
												<td><font face="Verdana" style="font-size: 8.5pt" color="#000000"><?php echo $x2[2];  ?></font><font color="#99CCFF" size="+1">&nbsp;&nbsp;&nbsp;</font></td>
												 <?php }?></tr>
												 <tr><td><font face="Verdana" style="font-size: 8.5pt" color="#000000"><b>Values&nbsp;</b></font></td>
												  <?php
												 $query3="select * from tbl_lookup_range_exception where form_id='".$x[0]."'";
												 $result3=mysql_query($query3);
												 
												
													while($x3=mysql_fetch_row($result3))
													{
												?>
												<td align="center"><font face="Verdana" style="font-size: 8.5pt" color="#000000"><?php echo $x3[3]; ?></font></td>
												 <?php }?>
												 </tr>
												 </table></td></tr>
                                                 <?php 
												 }
												 ?>										
													</table>
													 
													
												
											</td>
											
										</tr>
									</table>
								
					
					</td>
										
				</tr>
				
				
				<tr>
					<td align="center">
					<h5><font face="Verdana" style="font-size: 8.5pt" color="#000000">(Select User Type which you want to send mail)</font></h5>
					<input type="checkbox" name="ids1[]" id="ids1[]" value="'Management'">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">Management</font>&nbsp;
					<input type="checkbox" name="ids1[]" id="ids1[]" value="'Quality-Controler'">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">Quality Controler</font>&nbsp;
					<input type="checkbox" name="ids1[]" id="ids1[]" value="'Survey-Team'">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">Survey Team</font>&nbsp;
					<input type="checkbox" name="ids1[]" id="ids1[]" value="'Data-Entry-Operator'">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">Data Entry Operator</font>&nbsp;
					<input type="checkbox" name="ids1[]" id="ids1[]" value="'MIS-Team'">
					<font face="Verdana" style="font-size: 8.5pt" color="#000000">MIS</font>&nbsp;
					<p align="center"><input type="submit" value="Mail" name="mail" style="border:1px solid #000000; font-size: 8pt; font-family: Verdana; "></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
</table>
</form>					
</td>
    <td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
	<td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
</tr>

<tr>
                                  <td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
								  <td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
								  <td bgcolor="#E5E5E5" align="left" valign="top" colspan="5">
								    <font color="#000000" face="Verdana">
							        <span style="font-size: 8.5pt">
							         &nbsp;
						            </span></font></td>
								   <td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
								   <td bgcolor="#E5E5E5" align="left" valign="top">&nbsp;</td>
									
 </tr>
</table>
</body>
</html>
